
import * as XLSX from "xlsx"

export const exportExcel = (data:any,name:any) => {
  const worksheet = XLSX.utils.aoa_to_sheet(data)
  const workbook = XLSX.utils.book_new()
  XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1")
  const fileName = name ? `${name}.xlsx` : "output.xlsx" // 导出的文件名
  XLSX.writeFile(workbook, fileName)
}

export const handleExport = (arrExport:any,name:any) => {
  let excelData = [
    [
      "id",
      "昵称",
      "密码",
      "真名",
      "手机号",
      "年龄",
      "职业",
      "自我介绍",
      "是否会员",
      "头像",
      "地址",
      "角色",
      "创建时间",
      "是否删除",
      "性别",
      "邮箱",
    ]
  ]
  arrExport.forEach((item:any) => {
    let arr = []
    for(let key in item){
      arr.push(item[key])
    }
    excelData.push(arr)
    arr = []
  })
  
  exportExcel(excelData,name)
}



